package com.poorstu.web;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.DynaActionForm;

import com.common.base.web.BaseAction;
import com.poorstu.manager.ClassAndCollegeManager;
import com.poorstu.manager.LoginMeg;
import com.poorstu.manager.RoleManager;
import com.poorstu.model.CollegeMod;
import com.poorstu.model.LoginMod;
import com.poorstu.model.RoleMod;

public class SelectMenberByIdAction extends BaseAction {

	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		 
		try{
		DynaActionForm dyna=(DynaActionForm)form;
		int allUserId=(Integer)dyna.get("userId");
		
		LoginMeg login=(LoginMeg)getBean("loginMeg");
		LoginMod loginMod=login.selectUserById(allUserId);
		
		request.setAttribute("allUserId", allUserId);
		request.setAttribute("userName", loginMod.getName());
		request.setAttribute("userAccount", loginMod.getUserAccount());
		request.setAttribute("userPassword", loginMod.getPassword());
		
		request.setAttribute("roleId", loginMod.getRoleId().getRoleId());
		request.setAttribute("roleName", loginMod.getRoleId().getRoleName());
		
		request.setAttribute("classId", loginMod.getClassId().getClassId());
		request.setAttribute("className", loginMod.getClassId().getClassName());
		
		request.setAttribute("collegeId", loginMod.getClassId().getCollegeId().getCollegeId());
		request.setAttribute("collegeName", loginMod.getClassId().getCollegeId().getColName());
		
		RoleManager roleManager=(RoleManager)getBean("roleMeg");
		ClassAndCollegeManager classAndCollege=(ClassAndCollegeManager)getBean("classAndCollegeManager");
	
		List<CollegeMod> listCollege=classAndCollege.selectCollegeAll();
		request.setAttribute("listCollege", listCollege);
		
		List<RoleMod> listRole=roleManager.selectRoleAll();
		request.setAttribute("listRole", listRole);
		//classAndCollege
		
		  return mapping.findForward("succ");
		}catch(Exception e){
			e.printStackTrace();
			return mapping.findForward("failure");
		}
		
	}
	
	

}
